﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_Public;
using QLTV_BLL;

namespace QLTV_GiaoDien
{
    public partial class uc_PhieuMuonSach : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_PhieuMuonSach()
        {
            InitializeComponent();
        }
        public void GetLoad(int kt)
        {
            txt_Load.Text = kt.ToString();
        }
        PhieuMuon_BLL phieuMuon_bll = new PhieuMuon_BLL();

        private void uc_PhieuMuonSach_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = phieuMuon_bll.LayDuLieu();
            txt_Load.Hide();
            panelControl1.Hide();
        }
        private void bbi_Them_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_PhieuMuonSach f = new frm_PhieuMuonSach();
            f.Flag = 0;
            f.MyGetData = new frm_PhieuMuonSach.GetInt(GetLoad);
            f.ShowDialog();
        }
        private void bbi_Sua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_PhieuMuonSach f = new frm_PhieuMuonSach();
            f.Flag = 1;
            f.MyGetData = new frm_PhieuMuonSach.GetInt(GetLoad);
            f.MaPhieuMuon = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Phiếu Mượn").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.KieuMuon = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Kiểu Mượn").ToString();
            f.NgayMuon =Convert.ToDateTime( gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Lập").ToString());
            f.ShowDialog();
        }

        private void bbi_Xem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_PhieuMuonSach f = new frm_PhieuMuonSach();
            f.Flag = 2;
            f.MyGetData = new frm_PhieuMuonSach.GetInt(GetLoad);
            f.MaPhieuMuon = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Phiếu Mượn").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.KieuMuon = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Kiểu Mượn").ToString();
            f.NgayMuon = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Lập").ToString());
            f.ShowDialog();
        }
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            frm_PhieuMuonSach f = new frm_PhieuMuonSach();
            f.Flag = 2;
            f.MyGetData = new frm_PhieuMuonSach.GetInt(GetLoad);
            f.MaPhieuMuon = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Phiếu Mượn").ToString());
            f.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            f.KieuMuon = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Kiểu Mượn").ToString();
            f.NgayMuon = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ngày Lập").ToString());
            f.ShowDialog();
        }
        private void bbi_Xoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            PhieuMuon_Public pm = new PhieuMuon_Public();
            pm.MaPhieuMuon = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Phiếu Mượn").ToString());
            pm.MaDocGia = Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Độc Giả").ToString());
            if (XtraMessageBox.Show("Bạn có muốn xóa Mã phiếu mượn: '" + pm.MaPhieuMuon + "' có Mã độc giả: '" + pm.MaDocGia + "' này không?","Thông Báo",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
            {
                phieuMuon_bll.delete_PhieuMuon(pm);
                uc_PhieuMuonSach_Load(sender,e);
            }
        }

        private void bbi_Refresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_PhieuMuonSach_Load(sender,e);
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                uc_PhieuMuonSach_Load(sender,e);
                txt_Load.Text = "0";
            }
        }

        private void btn_Thoat_Click(object sender, EventArgs e)
        {
            panelControl1.Hide();
        }

        private void bbi_TimKiem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            panelControl1.Show();
        }

        private void btn_TimKiem_Click(object sender, EventArgs e)
        {

        }

        private void txt_MaPM_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
                e.Handled = true;
        }



    }
}
